﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTTemperatureAndHumidityService : ServiceHandle, IRPTTemperatureAndHumidity
    {
        #region IRPTTemperatureAndHumidity Members

        public OperationResult<List<tb_RPT_TemperatureAndHumidity>> GetAllTemperatureAndHumidity()
        {
            OperationResult<List<tb_RPT_TemperatureAndHumidity>> result = new OperationResult<List<tb_RPT_TemperatureAndHumidity>>();
            List<tb_RPT_TemperatureAndHumidity> list = new List<tb_RPT_TemperatureAndHumidity>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllTemperatureAndHumidity();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex); 
            }
            return result;
        }

        public OperationResult<List<tb_RPT_TemperatureAndHumidity>> GetTemperatureAndHumidityByContition(string strRecordDate, string strRecordTime, string strTemperature, string strHumidity, string strRecorder)
        {
            OperationResult<List<tb_RPT_TemperatureAndHumidity>> result = new OperationResult<List<tb_RPT_TemperatureAndHumidity>>();
            List<tb_RPT_TemperatureAndHumidity> list = new List<tb_RPT_TemperatureAndHumidity>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetTemperatureAndHumidityByContition(strRecordDate, strRecordTime,   
                                                                        strTemperature,   strHumidity,   strRecorder);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_TemperatureAndHumidity> GetTemperatureAndHumidityById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_TemperatureAndHumidity> result = new OperationResult<tb_RPT_TemperatureAndHumidity>();
            tb_RPT_TemperatureAndHumidity temperatureAndHumidity;
            try
            {
                temperatureAndHumidity = dataContext.GetTemperatureAndHumidityById(id);
                if (temperatureAndHumidity == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = temperatureAndHumidity;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_TemperatureAndHumidity> CreateTemperatureAndHumidity(tb_RPT_TemperatureAndHumidity entity)
        {
            OperationResult<tb_RPT_TemperatureAndHumidity> result = new OperationResult<tb_RPT_TemperatureAndHumidity>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateTemperatureAndHumidity(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_TemperatureAndHumidity> ModifyTemperatureAndHumidity(tb_RPT_TemperatureAndHumidity entity)
        {
            OperationResult<tb_RPT_TemperatureAndHumidity> result = new OperationResult<tb_RPT_TemperatureAndHumidity>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyTemperatureAndHumidity(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_TemperatureAndHumidity> DeleteTemperatureAndHumidity(tb_RPT_TemperatureAndHumidity entity)
        {
            OperationResult<tb_RPT_TemperatureAndHumidity> result = new OperationResult<tb_RPT_TemperatureAndHumidity>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteTemperatureAndHumidity(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
